fn main() {
    println!("Hello, world!");
}

#[cfg(test)]
mod tests {
    use std::{process::Command, thread::sleep, time::Duration};

    #[test]
    fn test_server_client() {
        let mut cargo_run = Command::new("cargo")
            .arg("build")
            .arg("--workspace")
            .spawn()
            .expect("Failed to start cargo run");
        cargo_run.wait().expect("Cargo run failed");

        let mut server = Command::new("./target/debug/server")
            .spawn()
            .expect("Failed to start server");
        sleep(Duration::from_secs(1));
        let input = std::fs::File::open("input.txt").expect("Failed to open input file");
        let mut client = Command::new("./target/debug/client")
            .stdin(input)
            .spawn()
            .expect("Failed to start client");
        client.wait().expect("Client crashed");
        sleep(Duration::from_secs(1));
        server.kill().expect("Failed to kill server");
    }

}
